//
//  TTIM_CaseCardCell.m
//  BaseProject
//
//  Created by 王洋 on 2020/9/3.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "TTIM_CaseCardCell.h"
#import "IM_CustomCaseModel.h"

@implementation TTIM_CaseCardCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor clearColor];

        _goodsImageView = [[UIImageView alloc] init];
        _goodsImageView.contentMode = UIViewContentModeScaleAspectFill;
        _goodsImageView.clipsToBounds = YES;
        [self.container addSubview:_goodsImageView];
        
        _goodsTitleLabel = [[UILabel alloc] init];
        _goodsTitleLabel.numberOfLines = 2;
        _goodsTitleLabel.font = [UIFont systemFontOfSize:15];
        [self.container addSubview:_goodsTitleLabel];

        self.container.backgroundColor = [UIColor whiteColor];
        [self.container.layer setMasksToBounds:YES];
        [self.container.layer setCornerRadius:5];
        
        
        [self.goodsImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.bottom.mas_equalTo(0);
            make.width.mas_equalTo(100);
        }];
        
        [self.goodsTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.goodsImageView.mas_right).offset(10);
            make.top.mas_equalTo(10);
            make.right.mas_equalTo(-10);
        }];

    }
    return self;
}

- (void)fillWithData:(TTIM_CaseCardCellData *)data {
    [super fillWithData:data];
    self.customData = data;
    
    NSDictionary *ext = data.model.ext;
    IM_CustomCaseModel *model = [IM_CustomCaseModel modelWithDictionary:ext];
    
    [self.goodsImageView sd_setImageWithURL:[NSURL URLWithString:model.opusUrl] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    self.goodsTitleLabel.text = model.opusName;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [self.avatarView pp_clipCorners:UIRectCornerAllCorners radius:4];
    });
}

@end
